#include "all_test_usb.h"
#include "ui_all_test_usb.h"
#include <QDebug>
#include <QScreen>

static int g_usbAddNum;
static int g_screenWidth;
static int g_screenHeight;

all_test_usb::all_test_usb(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::all_test_usb)
{
    ui->setupUi(this);
    QScreen *screen = qApp->primaryScreen();
    g_screenWidth = screen->size().width();
    g_screenHeight = screen->size().height();
    setAllTestUsbFont();
}

all_test_usb::~all_test_usb()
{
    delete ui;
}

void all_test_usb::on_btn_cancel_clicked()
{
    this->hide();
}

void all_test_usb::on_btn_ok_clicked()
{
     QString str = ui->comboBox->currentText();
     usb_num_msg(str.toInt());
     this->hide();
     g_usbAddNum = str.toInt();
}

void all_test_usb::showEvent(QShowEvent *event)
{
    ui->comboBox->setCurrentIndex(g_usbAddNum);
    QWidget::showEvent(event);
}

void all_test_usb::setAllTestUsbFont()
{
    QScreen *screen = qApp->primaryScreen();
    g_screenWidth = screen->size().width();
    qreal realX = screen->physicalDotsPerInchX();
    qreal realWidth = g_screenWidth / realX * 2.54;
    QFont font;
    if(realWidth < 15)
    {
        font.setPointSize(11);
    }
    else if (realWidth < 18)
    {
        font.setPointSize(13);
    }
    else
    {
        font.setPointSize(16);
    }

    ui->btn_cancel->setFont(font);
    ui->btn_ok->setFont(font);
    ui->lbl_title->setFont(font);
    ui->comboBox->setFont(font);
}

void all_test_usb::languageReload()
{
    ui->retranslateUi(this);
}
